package handlers

import (
	"github.com/gin-gonic/gin"
	"novel-ease/models"
)

func Login(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")
	if username == "" || password == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}
	var article models.User
	err := models.DB.Where("username=?", username).Create(&article).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "登录失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "登录成功",
		"data": Login,
	})
	return

}
func List(c *gin.Context) {

}
func Detail(c *gin.Context) {
	id := c.Query("id")
	var article models.Article
	err := models.DB.Where("id=?", id).Find(&article).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 200,
			"msg":  "查询失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": article,
	})
	return
}
